package com.leetcode.problems047;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * https://leetcode-cn.com/problems/jump-game-ii/
 * @Date 2021/12/09 14:34
 * @Author ghery
 * @Version V1.0
 */
public class Solution {
    List<List<Integer>> ans = new ArrayList<>();
    public List<List<Integer>> permuteUnique(int[] nums) {
        Arrays.sort(nums);
        permuteUnique(nums,new boolean[nums.length],new ArrayList<>(),0);
        return ans;
    }
    public void permuteUnique(int[] nums,boolean[] used,List<Integer> res,int index) {
        if(res.size() == nums.length){
            ans.add(new ArrayList<>(res));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if(used[i] || (i > 0 && nums[i] == nums[i - 1] && !used[i - 1])){
                continue;
            }
            res.add(nums[i]);
            used[i] = true;
            permuteUnique(nums, used, res,i);
            used[i] = false;
            res.remove(res.size() - 1);
        }
    }


    public static void main(String[] args) {
        int[] candidates = {1,1,2};
        System.out.println(new Solution().permuteUnique(candidates));
    }
}
